<template>
  <div id="root">
    <div class="todo-container">
      <div class="todo-wrap">
        <top :receice="receice"></top>
        <list :todos="todos" :change="change" :del="del"></list>
        <bottom :todos="todos" :checkAll="checkAll"></bottom>
      </div>
    </div>
    <student></student>
    <school></school>

<div>
    <div class="row">
      <div class="col-xs-offset-2 col-xs-8">
        <div class="page-header"><h2>Vue Router Demo</h2></div>
      </div>
    </div>
    <div class="row">
      <div class="col-xs-2 col-xs-offset-2">
        <div class="list-group">
          <router-link class="list-group-item" active-class="active" to="/about">About</router-link>
          <router-link class="list-group-item" active-class="active" to="/home">Home</router-link>
        </div>
      </div>
      <div class="col-xs-6">
        <div class="panel">
          <div class="panel-body">
            <router-view></router-view>
          </div>
        </div>
      </div>
    </div>
  </div>


  </div>
</template>
<script>
import Bottom from "./components/Bottom.vue";
import List from "./components/List.vue";
import School from './components/School.vue';
import Student from './components/Student.vue';
import Top from "./components/Top.vue";

export default {
  name: "App",
  components: {
    Top,
    List,
    Bottom,
    Student,
    School,
  },
  data() {
    return {
      todos: JSON.parse(localStorage.getItem("todos")),
    };
  },
  methods: {
    receice(x) {
      console.log("收到消息", x);
      this.todos.unshift(x);
    },
    change(id) {
      this.todos.forEach((element) => {
        if (element.id === id) {
          element.done = !element.done;
        }
      });
    },
    del(id) {
      this.todos = this.todos.filter((todo) => {
        return todo.id !== id;
      });
    },
    checkAll(done) {
      this.todos.forEach((todo) => {
        todo.done = done;
      });
    },
  },
  watch: {
    todos: {
      // 深度监视
      deep:true,
      handler(value) {
        localStorage.setItem("todos", JSON.stringify(value)) || [];
      },
    },
  },
};
</script>

<style>
/*base*/
body {
  background: #fff;
}
.btn {
  display: inline-block;
  padding: 4px 12px;
  margin-bottom: 0;
  font-size: 14px;
  line-height: 20px;
  text-align: center;
  vertical-align: middle;
  cursor: pointer;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.2),
    0 1px 2px rgba(0, 0, 0, 0.05);
  border-radius: 4px;
}
.btn-danger {
  color: #fff;
  background-color: #da4f49;
  border: 1px solid #bd362f;
}
.btn-danger:hover {
  color: #fff;
  background-color: #bd362f;
}
.btn:focus {
  outline: none;
}
.todo-container {
  width: 600px;
  margin: 0 auto;
}
.todo-container .todo-wrap {
  padding: 10px;
  border: 1px solid #ddd;
  border-radius: 5px;
}
</style>